﻿using PetaPoco;
using PmSoft;
using PmSoft.Caching;
using System.ComponentModel;

namespace Modules.Device.Entitys
{
    /// <summary>
    /// 身份证读卡记录
    ///</summary>
    [TableName("card_reader_record")]
    [Description("身份证读卡记录")]
    [PrimaryKey("id", AutoIncrement = true)]
    [CacheSetting(true)]
    [Serializable]
    public class CardReadRecord : IEntity
    {
        /// <summary>
        ///
        ///</summary>
        [Column("id")]
        public long Id { get; set; }

        /// <summary>
        /// 设备ID
        ///</summary>
        [Column("device_code")]
        public string DeviceCode { get; set; }

        /// <summary>
        /// 操作企业信用代码
        ///</summary>
        [Column("corp_code")]
        public string CorpCode { get; set; }

        /// <summary>
        /// 操作IP
        ///</summary>
        [Column("operation_ip")]
        public string OperationIp { get; set; }

        /// <summary>
        /// 设备信息
        ///</summary>
        [Column("deviceInfo")]
        public string DeviceInfo { get; set; }

        /// <summary>
        /// 读卡时间
        ///</summary>
        [Column("read_time")]
        public DateTime ReadTime { get; set; }

        /// <summary>
        /// 姓名
        ///</summary>
        [Column("name")]
        public string Name { get; set; }

        /// <summary>
        /// 性别
        ///</summary>
        [Column("sex")]
        public string Sex { get; set; }

        /// <summary>
        /// 民族
        ///</summary>
        [Column("race")]
        public string Race { get; set; }

        /// <summary>
        /// 生日
        ///</summary>
        [Column("birth")]
        public string Birth { get; set; }

        /// <summary>
        /// 身份证住址
        ///</summary>
        [Column("address")]
        public string Address { get; set; }

        /// <summary>
        /// 身份证号码
        ///</summary>
        [Column("card_id")]
        public string CardId { get; set; }

        /// <summary>
        /// 公司
        ///</summary>
        [Column("company")]
        public string Company { get; set; }

        /// <summary>
        /// 有效起始日期
        ///</summary>
        [Column("begin_date")]
        public DateTime? BeginDate { get; set; }

        /// <summary>
        /// 有效截至日期
        ///</summary>
        [Column("end_date")]
        public DateTime? EndDate { get; set; }

        #region IEntity 成员

        [Ignore]
        object IEntity.EntityId { get { return Id; } }

        #endregion IEntity 成员

        /// <summary>
        /// 是否包含设备信息
        /// </summary>
        /// <returns></returns>
        public bool HasDeviceInfo()
        {
            return !string.IsNullOrEmpty(DeviceInfo) && DeviceInfo != "[]";
        }
    }
}